package com.example.demo.mapper;

import com.example.demo.entity.Need;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface NeedMapper {

    @Select("select * from need where major=#{major} and term=#{term}")
    Need selectByMajorAndTerm(@Param("major")String major, @Param("term")String term);

    @Select("select * from need where college=#{college} and term=#{term}")
    List<Need> selectByCollegeAndTerm(@Param("college")String college, @Param("term")String term);

    @Select("select * from need where major=#{major}")
    List<Need> selectByMajor(String major);

    @Insert("<script>insert into need(college,major,need_course,gret,term,version)" +
            "<foreach collection = 'needs' item='record' separator=',' >" +
            " values(#{record.college},#{record.major},#{record.needCourse},#{record.gret},#{record.term},#{record.version})" +
            "</foreach></script>")
    int addMu(@Param("needs") List<Need> needs);

}
